<?php
class ORMCustomer extends ORMBase {
  public function __construct() {
    parent::__construct('Customer');
  }

  public function __toEpObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMCustomerContact.class.php';
    require_once dirname(__FILE__) . '/ORMMyOrder.class.php';
    require_once dirname(__FILE__) . '/ORMUser.class.php';
    $epObject->trackId = isset($object->trackId) ? $object->trackId : '';
    $epObject->createdDate = isset($object->createdDate) ? SimpleDate::toStamp($object->createdDate) : 0;
    if (isset($object->sales) && $object->sales) {
        $epObject->sales = $this->__getEpObject_4_lvl_1_object($myManager, $object->sales, new ORMUser(), 'User');
    } else {
      if (isset($epObject->sales)) {
        $my_manager->delete($epObject->sales);
      }
    }
    if (isset($object->bride) && $object->bride) {
        $epObject->bride = $this->__getEpObject_4_lvl_1_object($myManager, $object->bride, new ORMCustomerContact(), 'CustomerContact');
    } else {
      if (isset($epObject->bride)) {
        $my_manager->delete($epObject->bride);
      }
    }
    if (isset($object->groom) && $object->groom) {
        $epObject->groom = $this->__getEpObject_4_lvl_1_object($myManager, $object->groom, new ORMCustomerContact(), 'CustomerContact');
    } else {
      if (isset($epObject->groom)) {
        $my_manager->delete($epObject->groom);
      }
    }
    $epObject->note = isset($object->note) ? $object->note : '';
    $epObject->source = isset($object->source) ? $object->source : '';
    if (isset($epObject->orders)) {
      $epObject->orders->removeAll();
      foreach ($object->orders as &$item) {
        $epObject->orders[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMMyOrder(), 'MyOrder');
      }
    }
    return $epObject;
  }

  public function __toObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMCustomerContact.class.php';
    require_once dirname(__FILE__) . '/ORMMyOrder.class.php';
    require_once dirname(__FILE__) . '/ORMUser.class.php';
    $object->id = $epObject->oid;
    $object->trackId = $epObject->trackId;
    $object->createdDate = SimpleDate::fromStamp($epObject->createdDate);
    if (isset($epObject->sales)) {
      $object->sales = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->sales, new ORMUser());
    }
    if (isset($epObject->bride)) {
      $object->bride = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->bride, new ORMCustomerContact());
    }
    if (isset($epObject->groom)) {
      $object->groom = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->groom, new ORMCustomerContact());
    }
    $object->note = $epObject->note;
    $object->source = $epObject->source;
    $object->orders = array();
    if (isset($epObject->orders)) {
      foreach ($epObject->orders as &$item) {
        $object->orders[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMMyOrder());
      }
    }
    return $object;
  }
}
?>
